<template>
	<view class="all-main">
		<view class="main">
			<u-sticky>
				<view class="search">
					<view class="search-input">
						<u-search placeholder="终端号" shape="square" bgColor="#ffffff" :showAction="false" v-model="keyword"></u-search>
					</view>
					<view class="search-product" @click="productShow = true">
						<text>{{productName}}</text>
						<u-icon name="list-dot" color="#2979ff" size="24"></u-icon>
					</view>
				</view>
			</u-sticky>
			<view v-if="lists.length > 0" class="lists">
				<view v-for="(item, index) in lists" :key="index" class="items">
					<view class="titles">
						<view class="sn">
							<text>{{item.sn}}</text>
						</view>
						<view class="standard-state">
						</view>
					</view>
					<view v-if="item.terminal.merchant_name" class="merchant-info">
						<view class="lefts">
							<text>商户名称</text>
						</view>
						<view class="rights">
							<text>{{item.terminal.merchant_name}}</text>
						</view>
					</view>
					<view class="merchant-info">
						<view class="lefts">
							<text>订单编号</text>
						</view>
						<view class="rights">
							<text>{{item.order_no}}</text>
						</view>
					</view>
					<view class="merchant-info">
						<view class="lefts">
							<text>押金金额</text>
						</view>
						<view class="rights">
							<text class="reds">{{item.deposit_amount}}</text>
						</view>
					</view>
					<view v-if="item.terminal.bind_time" class="merchant-info bottoms">
						<view class="lefts">
							<text>时间</text>
						</view>
						<view class="rights">
							<text>{{item.create_time}}</text>
						</view>
					</view>
				</view>
			</view>
			<u-empty v-else mode="list" icon="/static/Empty/data_null.png">
			</u-empty>
			<u-picker :show="productShow" :columns="productList" keyName="title" @confirm="proConfirm"
				@cancel="productShow = false"></u-picker>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				page: 1,
				page_size: 10,
				bottom: true,
				lists: [],
				productShow: false,
				productList: [],
				product_id: '',
				productName: '全部',
			}
		},
		onLoad() {
			this.loadData()
			this.getHzyProduct()
		},
		filters: {
			formatDate(value) {
				if (value) {
					return new Date(value * 1000).toLocaleString(); // 转换为本地日期和时间字符串
				}
			}
		},
		//上拉加载
		onReachBottom() {
			if (this.bottom == true) {
				this.page += 1
				this._other()
			}
		},
		methods: {
			// 产品选择
			proConfirm(e) {
				if (this.product_id != e.value[0].id) {
					this.product_id = e.value[0].id
					this.productName = e.value[0].title
					this.productShow = false
					this.page = 1
					this.bottom = true
					this.lists = []
					this.loadData()
				} else {
					this.productShow = false
				}
			},
			// 获取产品
			async getHzyProduct() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getHzyProduct',
				});
				if (res.code == 200) {
					this.productList = [res.data]
				}
			},
			// 加载数据
			async loadData() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getHzyDepositList',
					data: {
						page_size: 15,
						page: this.page,
						keyword: this.keyword,
						product_id: this.product_id
					},
				});
				uni.hideLoading()
				if (res.code == 200) {
					if (res.data.data !== undefined && res.data.data !== null && res.data.data.length >
						0) {
						if (this.page == 1) {
							this.lists = res.data.data
						} else {
							this.lists = [...this.lists, ...res.data.data]
						}
						this.display = true
					} else {
						this.bottom = false
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.all-main {
		.main {
			.search {
				padding: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: #F2F6FC;
				
				.search-input {
					width: 70%;
				}
				
				.search-product {
					width: 30%;
					display: flex;
					justify-content: flex-end;
					align-items: center;
					font-size: 24rpx;
					
					text {
						padding-right: 10rpx;
					}
				}
			}
			
			.state-tag {
				padding: 0 30rpx 30rpx 30rpx;
			}
			
			.lists {
				padding: 0 30rpx;
				
				.items {
					background-color: #ffffff;
					border-radius: 16rpx;
					box-shadow: 7px 0px 30px -18px #888888;
					
					.titles {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 30rpx;
						border-bottom: 1px solid #F2F6FC;
						
						.sn {
							font-weight: bold;
						}
						
						.standard-state {
							font-size: 28rpx;
						}
					}
					
					.reds {
						color: #fa3534;
					}
					
					.greens {
						color: #19be6b;
					}
					
					.warms {
						color: #ff9900;
					}
					
					.merchant-info {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 20rpx 30rpx 0 30rpx;
						font-size: 28rpx;
						
						.rights {
							color: #909399;
							
							.reds {
								font-weight: bold;
								color: #fa3534;
							}
						}
					}
					
					.bottoms {
						padding-bottom: 30rpx;
					}
					
					.standard-list {
						margin-top: 30rpx;
						padding: 0 30rpx;
						padding-bottom: 30rpx;
						border-top: 1px solid #F2F6FC;
						
						.standard-item {
							margin-top: 20rpx;
							border: 1px dashed #F2F6FC;
							padding: 20rpx;
							
							.standard-titles {
								padding-bottom: 20rpx;
								display: flex;
								border-bottom: 1px dashed #F2F6FC;
								justify-content: space-between;
							}
							
							.standard-info {
								display: flex;
								align-items: center;
								
								.days {
									width: 25%;
								}
								
								.trades {
									width: 60%;
									text-align: right;
								}
								
								.state-icon {
									width: 15%;
									display: flex;
									justify-content: flex-end;
								}
								
								.tags {
									padding: 0 8rpx;
								}
								
								.units {
									font-size: 24rpx;
									color: #909399;
								}
							}
						}
					}
				}
			}
		}
	}
</style>
